

package edu.tfg.bean;


import edu.tfg.dao.ClienteDAO;
import edu.tfg.model.Cliente;
import java.util.List;
import java.util.Objects;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Juarez
 */
@ManagedBean
@SessionScoped
public class ClienteBean {
    
    private Cliente cliente = new Cliente();
    private ClienteDAO clienteDAO = new ClienteDAO();
    private List listaClientes;
    
    public ClienteBean() {
    }

    public List getListaClientes() {
        return listaClientes;
    }

    public void setListaClientes(List listaClientes) {
        this.listaClientes = listaClientes;
    }

    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    public ClienteDAO getClienteDAO() {
        return clienteDAO;
    }

    public void setClienteDAO(ClienteDAO clienteDAO) {
        this.clienteDAO = clienteDAO;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 47 * hash + Objects.hashCode(this.cliente);
        hash = 47 * hash + Objects.hashCode(this.clienteDAO);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ClienteBean other = (ClienteBean) obj;
        if (!Objects.equals(this.cliente, other.cliente)) {
            return false;
        }
        if (!Objects.equals(this.clienteDAO, other.clienteDAO)) {
            return false;
        }
        return true;
    }

    public String adicionaCliente(){
        clienteDAO.salvar(cliente);
        return "index";
    }

     public String removeCliente(Cliente c){
        this.cliente = c;
        clienteDAO.removeCliente(this.cliente);
        return "index";
     }
    
     public List listarClientes(){
         listaClientes = clienteDAO.listarClientes();
         return listaClientes;
     }
     public String alterarCliente(){
            clienteDAO.alterar(cliente);
         return "index";
     }
     
     public String pesquisarCliente(){
         clienteDAO.pesquisar(null);
         return "index";
     }
     
     
}
     
